package daos.auto.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import model.entities.Auto;
import daos.AbstractDAO;
import daos.auto.AutoDAO;
import daos.db.Conexion;

public class AutoDAOImpl extends AbstractDAO implements AutoDAO{
	
	Conexion con = new Conexion();

	public void insert(Auto auto) throws SQLException {
		
		String insertSql = "INSERT INTO AUTOS (MODELO, PATENTE, COLOR, MARCA, DETALLE) VALUES (?,?,?,?,?)";
		PreparedStatement stmt = null;
		Connection conex = null;
		try {

			conex = con.getConnected();
			stmt = conex.prepareStatement(insertSql);
			
			stmt.setInt(1, auto.getModelo());
			stmt.setString(2, auto.getPatente());
			stmt.setString(3, auto.getColor());
			stmt.setString(4, auto.getMarca());
			stmt.setString(5, auto.getDetalle());

			System.out.println(insertSql);

			stmt.executeUpdate();
			System.out.println("Row inserted OK");

		} finally {
			closeConnection(conex, stmt, null);
		}
	}
	
	public void delete(Auto auto) throws SQLException {
		String deleteSql = "DELETE FROM AUTOS WHERE PATENTE = ?";
		PreparedStatement stmt = null;
		Connection conex = null;
		try {

			conex = con.getConnected();
			stmt = conex.prepareStatement(deleteSql);
			
			stmt.setString(1, auto.getPatente());

			System.out.println(deleteSql);

			stmt.executeUpdate();
			System.out.println("Row deleted OK");

		} finally {
			closeConnection(conex, stmt, null);
		}
	}
	
	public List<Auto> selectAll() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Auto selectByPatente(Auto auto) throws SQLException {
		String selectSql = "SELECT * FROM AUTOS WHERE PATENTE = ?";
		PreparedStatement stmt = null;
		Connection conex = null;
		try {

			conex = con.getConnected();
			stmt = conex.prepareStatement(selectSql);
			
			stmt.setString(1, auto.getPatente());

			System.out.println(selectSql);

			stmt.executeUpdate();
			System.out.println("Row selected OK");
return null;
		} finally {
			closeConnection(conex, stmt, null);
		}
	}
}
